package com.atguigu.juc.day02.lock;

import java.util.concurrent.TimeUnit;

public class Demo06Interrupt {

    public static void main(String[] args) throws InterruptedException {

        // 创建线程对象
        Thread thread = new Thread(() -> {
            try {
                // 执行过程中睡一会儿
                Thread.sleep(100000);
            } catch (InterruptedException e) {
                System.out.println(Thread.currentThread().getName() + " 睡觉被打断了。");
            }
        }, "thread-a");

        // 启动线程
        thread.start();

        // 主线程在 5 秒之后尝试打断 thread 线程对象的睡眠状态
        TimeUnit.SECONDS.sleep(5);

        // 执行打断
        thread.interrupt();

    }

}
